home *** CD-ROM | disk | FTP | other *** search
/ Small Time Crooks Press Kit / Small Time Crooks Press Kit.iso / pc / Small Time Crooks.dxr / Scripts_20_Add-Remove Items Behavior.ls < prev    next >
Encoding:
Text File  |  2000-04-30  |  5.2 KB  |  170 lines

  1. property pScript, pGroupName, pMasterListName, pList2Name, pItemToStringHandler, pIncludeRoll, pList1, pList2, pMasterList, pFunction, pField1, pField2, pFieldObj1, pFieldObj2, pSprite2, pSelection, ancestor
  2.  
  3. on beginSprite me
  4.   set pScript to "Add-Remove Items Behavior"
  5.   do("global" && pMasterListName)
  6.   set pMasterList to value(pMasterListName)
  7.   do("global" && pList2Name)
  8.   set pList2 to value(pList2Name)
  9.   set pList1 to SubtractLists(pMasterList, pList2)
  10.   set memberName to the name of the member of sprite the spriteNum of me
  11.   case 1 of
  12.     (memberName contains "Available"):
  13.       set pFunction to #field1
  14.     (memberName contains "Selected"):
  15.       set pFunction to #field2
  16.   end case
  17.   case pFunction of
  18.     #field1, #field2:
  19.       set ancestor to new(script "Single State But", the spriteNum of me)
  20.   end case
  21.   case pFunction of
  22.     #field1:
  23.       set pField1 to the number of the member of sprite the spriteNum of me
  24.       set pFieldObj1 to me
  25.       set field1String to GetFieldString(1)
  26.       put field1String into field pField1
  27.     #field2:
  28.       set pField2 to the number of the member of sprite the spriteNum of me
  29.       set pFieldObj2 to me
  30.       set field2String to GetFieldString(2)
  31.       put field2String into field pField2
  32.   end case
  33.   share(me, [#pList1, #pField1, #pField2, #pFieldObj1, #pFieldObj2])
  34. end
  35.  
  36. on share me, propsToShare
  37.   set maxSprite to the spriteNum of me
  38.   repeat with n = 1 to count(propsToShare)
  39.     set prop to getAt(propsToShare, n)
  40.     if voidp(getaProp(me, prop)) then
  41.       setaProp(me, prop, FindSpriteProp(maxSprite, [#pScript: pScript, #pGroupName: pGroupName], prop))
  42.       next repeat
  43.     end if
  44.     SetSpriteProp(maxSprite - 1, [#pScript: pScript, #pGroupName: pGroupName], [prop, getaProp(me, prop)])
  45.   end repeat
  46. end
  47.  
  48. on MouseUpAction me
  49.   nothing()
  50. end
  51.  
  52. on MouseDownAction me
  53.   case pFunction of
  54.     #field1, #field2:
  55.       if the doubleClick then
  56.         MoveLine(me)
  57.       end if
  58.   end case
  59. end
  60.  
  61. on MouseEnterAction me
  62.   nothing()
  63. end
  64.  
  65. on MouseLeaveAction me
  66.   nothing()
  67. end
  68.  
  69. on MoveLine me
  70.   if pFunction = #field1 then
  71.     set theList to pList1
  72.     set theField to pField1
  73.     set otherField to pField2
  74.   else
  75.     set theList to pList2
  76.     set theField to pField2
  77.     set otherField to pField1
  78.   end if
  79.   if not count(theList) then
  80.     exit
  81.   end if
  82.   set clickLine to the mouseLine
  83.   if clickLine < 1 then
  84.     exit
  85.   end if
  86.   set pSelection to [getAt(theList, clickLine)]
  87.   if pFunction = #field1 then
  88.     add(me)
  89.   else
  90.     remove(me)
  91.   end if
  92. end
  93.  
  94. on add me
  95.   set listToAdd to the pSelection of pFieldObj1
  96.   set pList1 to SubtractLists(pList1, listToAdd)
  97.   set newList2 to SubtractLists(pMasterList, pList1)
  98.   set theCount to count(pList2)
  99.   repeat with n = theCount down to 1
  100.     deleteAt(pList2, n)
  101.   end repeat
  102.   repeat with listItem in newList2
  103.     append(pList2, listItem)
  104.   end repeat
  105.   set field1String to GetFieldString(1)
  106.   set field2String to GetFieldString(2)
  107.   put field1String into field pField1
  108.   put field2String into field pField2
  109.   set the pList1 of pFieldObj1 to pList1
  110.   set the pList1 of pFieldObj2 to pList1
  111. end
  112.  
  113. on remove me
  114.   set listToRemove to the pSelection of pFieldObj2
  115.   set newList2 to SubtractLists(pList2, listToRemove)
  116.   set theCount to count(pList2)
  117.   repeat with n = theCount down to 1
  118.     deleteAt(pList2, n)
  119.   end repeat
  120.   repeat with listItem in newList2
  121.     append(pList2, listItem)
  122.   end repeat
  123.   set pList1 to SubtractLists(pMasterList, pList2)
  124.   set field1String to GetFieldString(1)
  125.   set field2String to GetFieldString(2)
  126.   put field1String into field pField1
  127.   put field2String into field pField2
  128.   set the pList1 of pFieldObj1 to pList1
  129.   set the pList1 of pFieldObj2 to pList1
  130. end
  131.  
  132. on GetFieldString whichField
  133.   set fieldString to EMPTY
  134.   if whichField = 1 then
  135.     set theList to pList1
  136.   else
  137.     set theList to pList2
  138.   end if
  139.   repeat with listItem in theList
  140.     set itemString to EMPTY
  141.     do("set itemString =" && pItemToStringHandler & "(listItem)")
  142.     put itemString & RETURN after fieldString
  143.   end repeat
  144.   delete char -30003 of fieldString
  145.   return fieldString
  146. end
  147.  
  148. on getPropertyDescriptionList me
  149.   set description to [:]
  150.   addProp(description, #pGroupName, [#default: "Add_Remove_Download_Texts", #format: #string, #comment: "Group Name"])
  151.   addProp(description, #pMasterListName, [#default: "gMasterTexts", #format: #string, #comment: "Variable Name of List of All Items"])
  152.   addProp(description, #pList2Name, [#default: "gDownloadTexts", #format: #string, #comment: "Variable Name of List of Selected Items"])
  153.   addProp(description, #pItemToStringHandler, [#default: "GetTextDescription", #format: #string, #comment: "Name of List-Item-To-String Conversion Handler"])
  154.   addProp(description, #pIncldRoll, [#default: 1, #format: #boolean, #comment: "Buttons Include Rollover"])
  155.   return description
  156. end
  157.  
  158. on getBehaviorDescription me
  159.   set endChar to offset("--END OF HEADER", the text of me)
  160.   set endLine to the number of lines in char 1 to endChar of the text of me - 1
  161.   set description to line 1 to endLine of the text of me
  162.   repeat with whichLine = endLine down to 1
  163.     if line whichLine of description = EMPTY then
  164.       delete line whichLine of description
  165.     end if
  166.   end repeat
  167.   delete line 1 of description
  168.   return description
  169. end
  170.